package demo.concurrent.queue;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.SynchronousQueue;

/**
 * 队列的使用
 */
public class QueueDemo {

    public static void main(String[] args) throws InterruptedException {
        synchronousQueueDemo();
    }

    public static void synchronousQueueDemo() throws InterruptedException {
        SynchronousQueue<Object> queue = new SynchronousQueue<>(true);
        ArrayBlockingQueue<Object> blockingQueue = new ArrayBlockingQueue<Object>(6);
        new Thread(() -> {
            try {
                Thread.sleep(5000);
                queue.put("1");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
        new Thread(() -> {
            try {
                System.out.println(queue.take());
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }).start();
        Thread.currentThread().join();
    }

}
